package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysVolunteers;
import com.ruoyi.system.service.ISysVolunteersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿者Controller
 * 
 * @author zk
 * @date 2021-11-08
 */
@Controller
@RequestMapping("/system/volunteers")
public class SysVolunteersController extends BaseController
{
    private String prefix = "system/volunteers";

    @Autowired
    private ISysVolunteersService sysVolunteersService;

    @RequiresPermissions("system:volunteers:view")
    @GetMapping()
    public String volunteers()
    {
        return prefix + "/volunteers";
    }

    /**
     * 查询志愿者列表
     */
    @RequiresPermissions("system:volunteers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysVolunteers sysVolunteers)
    {
        startPage();
        List<SysVolunteers> list = sysVolunteersService.selectSysVolunteersList(sysVolunteers);
        return getDataTable(list);
    }

    /**
     * 导出志愿者列表
     */
    @RequiresPermissions("system:volunteers:export")
    @Log(title = "志愿者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysVolunteers sysVolunteers)
    {
        List<SysVolunteers> list = sysVolunteersService.selectSysVolunteersList(sysVolunteers);
        ExcelUtil<SysVolunteers> util = new ExcelUtil<SysVolunteers>(SysVolunteers.class);
        return util.exportExcel(list, "志愿者数据");
    }

    /**
     * 新增志愿者
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存志愿者
     */
    @RequiresPermissions("system:volunteers:add")
    @Log(title = "志愿者", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysVolunteers sysVolunteers)
    {
        return toAjax(sysVolunteersService.insertSysVolunteers(sysVolunteers));
    }

    /**
     * 修改志愿者
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysVolunteers sysVolunteers = sysVolunteersService.selectSysVolunteersById(id);
        mmap.put("sysVolunteers", sysVolunteers);
        return prefix + "/edit";
    }

    /**
     * 修改保存志愿者
     */
    @RequiresPermissions("system:volunteers:edit")
    @Log(title = "志愿者", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysVolunteers sysVolunteers)
    {
        return toAjax(sysVolunteersService.updateSysVolunteers(sysVolunteers));
    }

    /**
     * 删除志愿者
     */
    @RequiresPermissions("system:volunteers:remove")
    @Log(title = "志愿者", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysVolunteersService.deleteSysVolunteersByIds(ids));
    }
}
